//
//  KyStatusListViewModel.swift
//  KySwiftPro
//
//  Created by fangyukui on 2017/10/24.
//  Copyright © 2017年 fangyukui. All rights reserved.
//

import UIKit
import YYModel
class KyStatusListViewModel {
    lazy var statusList = [KyStatusModel]()
    func getStatus(isPullup:Bool,complete:@escaping (_ isSucess:Bool)->())  {
        let since_id = isPullup ? 0 : statusList.first?.id ?? 0  //下拉最新的数据
        let max_id = !isPullup ? 0 : statusList.last?.id ?? 0    //上拉历史的数据
        
        KyNetworkManager.shared.getStatues(since_id: since_id, max_id: max_id) { (json, isSucess) in
            guard let items =  NSArray.yy_modelArray(with: KyStatusModel.self, json: json ?? []) as? [KyStatusModel] else
            {
                complete(isSucess)
                return
                
            }
            if isPullup == true{
                self.statusList += items
            }else{
                self.statusList = items + self.statusList
            }
            
            complete(isSucess)
        }
    }
    

}
